package edu.java.homework.hw08.ipj10.exer01done;

/**
 * @author Tsvetan Vasilev
 * 
 */

/*
 * I thought to create a factory but in fact I put the check in set-methods.
 * There aren't any other itialize operations. So creation of a factory is
 * inappropriate.
 */

public class Worker {

    // --- Instance Variables --------------------------------------------------
    private String name = null;
    private int[] PIN = null;
    private Appointment appointment = null;
    double salary = 0.0d;

    // --- Constructors --------------------------------------------------------

    public Worker() {
	name = new String();
	PIN = new int[10];
	appointment = Appointment.DEFAULT_APPOINTMENT;
	salary = 0.0d;
    }

    public Worker(String name, int[] pin, Appointment appointment, double salary) {
	setName(name);
	setPIN(pin);
	setAppointment(appointment);
	setSalary(salary);
    }

    // --- Getters and Setters -------------------------------------------------

    public String getName() {
	return name;
    }

    public void setName(String name) {
	// check formal parametar
	if (name == null) {
	    throw new IllegalArgumentException(
		    "The input string object for name is null-pointed");
	}
	this.name = name;
    }

    public int[] getPIN() {
	return PIN;
    }

    public void setPIN(int[] pin) {
	// check for null-point exception
	if (pin == null) {
	    throw new IllegalArgumentException("The PIN array is null-pointed.");
	}

	// check length
	if (pin.length != 10) {
	    throw new IllegalArgumentException(
		    "Incorrect number of ciphers in PIN.");
	}

	// check ciphers in PIN
	for (int i : pin) {
	    if (i < 0 || i > 10) {
		throw new IllegalArgumentException("Incorrect ciphers in PIN.");
	    }
	}
	// assignment
	PIN = pin;
    }

    public Appointment getAppointment() {
	return appointment;
    }

    public void setAppointment(Appointment appointment) {
	// check formal parametars
	if (appointment == null) {
	    throw new IllegalArgumentException(
		    "The Appointment object is null-pointed");
	}

	this.appointment = appointment;
    }

    public double getSalary() {
	return salary;
    }

    public void setSalary(double salary) {
	// check formal parametars
	if (salary < 0) {
	    throw new IllegalArgumentException(
		    "Incorrect amount of the salary. The salary is positive number");
	}
	this.salary = salary;
    }

    // --- Methods -------------------------------------------------------------

    @Override
    public String toString() {
	StringBuilder sb = new StringBuilder();
	sb.append("Name: " + getName() + "\t");
	sb.append("Appointment: " + getAppointment() + "\t");
	sb.append("Salary: " + getSalary());

	return sb.toString();
    }

}
